package com.iqik.base.mongo_db;

import com.mongodb.Block;
import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

public class MongoDBDemo {

    public static void main(String[] args) {
        MongoClient mongoClient = new MongoClient("132.232.16.135", 27017);
        MongoDatabase demoDatabase = mongoClient.getDatabase("demo_db");
        MongoCollection<Document> resumePreview = demoDatabase.getCollection("resume_preview");
        Document document = Document.parse(
                "{name: 'iqik', city: 'beijing', birth_day: new ISODate('1995-02-26'), " +
                        "expectSalary: 25555}");
        resumePreview.insertOne(document);

        FindIterable<Document> documents = resumePreview.find();
        documents.forEach((Block<? super Document>) doc -> {
//            System.out.println(doc.toJson());
            System.out.println(doc);
        });
        mongoClient.close();
    }

}
